package com.java.score

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class MyViewModel: ViewModel() {
    //init score
     val scoreA:MutableLiveData<Int> by lazy { MutableLiveData<Int>().also { it.value = 0 } }
     val scoreB:MutableLiveData<Int> by lazy { MutableLiveData<Int>().also { it.value = 0 } }
    //temp data
    private var tempA:Int = 0
    private var tempB:Int = 0
    //plus
    fun plusA(n:Int){
        tempA = scoreA.value!!
        tempB = scoreB.value!!
        scoreA.value = scoreA.value?.plus(n)
    }
    // B plus
    fun plusB(n:Int){
        tempA = scoreA.value!!
        tempB = scoreB.value!!
        scoreB.value = scoreB.value?.plus(n)
    }
    //function redo
    fun redo(){
        scoreA.value = tempA
        scoreB.value = tempB
    }

    //function reset
    fun reset(){
        tempA = scoreA.value!!
        tempB = scoreB.value!!
        scoreA.value = 0
        scoreB.value = 0
    }
}